﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MovieRental.BuisnessComponents.Helpers
{
    public static class SearchHelper
    {
        public static int GetSimilarWordsCoefficient(this string sourceString, string searchString)
        {
            int coef = 0;
            string[] sourceWords = sourceString.Split(' ');
            string[] searchWords = searchString.Split(' ');
            foreach (string w in sourceWords)
            {
                if (searchWords.Any(x => x.Equals(w, StringComparison.OrdinalIgnoreCase)))
                    coef += 2;
                else if (searchWords.Any(x => w.ToLower().Contains(x.ToLower())))
                    coef += 1;
            }
            return coef;  
        }
    }
}
